#ifndef THREADLOCKER_H
#define THREADLOCKER_H

#include <pthread.h>
#include <exception>


class threadlocker
{
private:
    /* data */
    pthread_mutex_t mutex;
public:
    threadlocker(/* args */)
    {
        if(pthread_mutex_init(&mutex,NULL) != 0)
            throw std::exception();
    }
    ~threadlocker()
    {
        pthread_mutex_destroy(&mutex);
    }

    bool lock()
    {
        return pthread_mutex_lock(&mutex)==0;
    }

    bool unlock()
    {
        return pthread_mutex_unlock(&mutex)==0;
    }

    pthread_mutex_t *get()
    {
        return &m_mutex;
    }
};
#endif